<?php

abstract class JFactory
{
    /**
     * @return ShoppingCart
     */
    public static function getShoppingCart()
    {
        $shoppingCart = JSession::getShoppingCart();
        if (isset($shoppingCart)) {
            return $shoppingCart;
        } else {
            $shoppingCart = ShoppingCart::getInstance();
            JSession::setShoppingCart($shoppingCart);
            return $shoppingCart;
        }
    }

    /**
     * @param int $id
     * @return JUser
     */
    public static function getUser($id = 0)
    {
        if ($id == 0) {
            $user = JSession::getUser();
            if ($user instanceof JUser) {
                return $user;
            } else {
                return JUser::getInstance();
            }
        } else {
            $user = JSession::getUser();
            if ($user instanceof JUser && $user->ID = $id) {
                return $user;
            } else {
                return JUser::getInstance($id);
            }
        }
    }
}
